package com.jinlejia.erp.ui.mine.contract;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.jinlejia.erp.R;
import com.jinlejia.erp.databinding.ActivityRejectSelectReasonBinding;

import net.idik.lib.slimadapter.SlimAdapter;
import net.idik.lib.slimadapter.SlimInjector;
import net.idik.lib.slimadapter.viewinjector.IViewInjector;

import java.util.ArrayList;

/**
 * 审核驳回原因选择
 */
public class RejectSelectReasonActivity extends AppCompatActivity {
    private SlimAdapter slimAdapter;
    ArrayList<String> selectList = new ArrayList<>();

    private ActivityRejectSelectReasonBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_reject_select_reason);
        binding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        binding.recyclerView.setHasFixedSize(true);
        binding.backBtn.setOnClickListener(view -> {
            Intent data = new Intent();
            data.putStringArrayListExtra("reason", selectList);
            setResult(RESULT_OK, data);
            finish();
            finish();
        });
        slimAdapter = SlimAdapter.create()
                .register(R.layout.item_reject_reason_layout, new SlimInjector<String>() {
                    @Override
                    public void onInject(final String data, IViewInjector injector) {
                        injector.text(R.id.text, data)
                                .clicked(R.id.layout_item, new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        if (selectList.contains(data)) {
                                            selectList.remove(data);
                                        } else {
                                            selectList.add(data);
                                        }
                                        slimAdapter.notifyItemChanged(slimAdapter.getData().indexOf(data));
                                    }
                                })
                                .checked(R.id.checkbox, selectList.contains(data));
                    }
                }).attachTo(binding.recyclerView);


        slimAdapter.updateData(getIntent().getStringArrayListExtra("rejectReasonList"));


    }

}
